package com.hst.capacity.infra.persistence.jpa.setting.station;

import com.hst.capacity.domain.model.entity.setting.airport.AirportEntity;
import com.hst.capacity.domain.model.entity.setting.railway.RailwayEntity;
import com.hst.capacity.domain.model.entity.setting.station.StationEntity;
import com.hst.capacity.domain.model.response.setting.AirportVO;
import com.hst.capacity.domain.model.response.setting.RailStationVO;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface RailStationRepository extends CrudRepository<RailwayEntity, String> {

    /**
     * 通过地区CODE查找运营火车站
     * @param code
     * @return
     */
    List<RailwayEntity> findByCityCode(String code);

    RailwayEntity findByCityCodeAndName(String cityCode, String name);

    RailwayEntity findByIdStation(String idStation);

    /**
     * 通过地区CODE查找火车站
     * @param cityCode
     * @return
     */
    @Query("SELECT new com.hst.capacity.domain.model.response.setting.RailStationVO(t) FROM RailwayEntity t WHERE t.cityCode=:cityCode")
    List<RailStationVO> findByCode(String cityCode);

    /**
     * 火车站查找
     * @param cityCode
     * @param name
     * @return
     */
    @Query("SELECT t FROM RailwayEntity t WHERE t.cityCode=:cityCode AND t.name like concat('%',:name,'%') ")
    List<RailwayEntity> findByRailwayName(String cityCode, String name);

}
